<!DOCTYPE html>
<html>
<head>
    <title>模具维修记录</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <i-form ref="formValidate" :label-width="100" style="margin-top: 20px">
        <Row>
            <i-col span="11">
                <Form-item label="模具号" prop="moldNo">
                    <i-input v-model="moduleRepairRocord.moduleNo" placeholder="模具号" icon="md-arrow-dropdown-circle" @on-click="getModuleArchives"></i-input>
                </Form-item>
            </i-col>
            <i-col span="11">
                <Form-item label="报修时间" prop="repairDate">
                    <i-input v-model="moduleRepairRocord.repairDate" disabled></i-input>
                </Form-item>
            </i-col>
        </Row>
        <Row>
            <i-col span="11">
                <Form-item label="开始维修时间" prop="orderExecuteDate">
                    <Date-picker v-model="moduleRepairRocord.orderExecuteDate" type="datetime" placeholder="开始维修时间" :transfer="true"></Date-picker>
                </Form-item>
            </i-col>
            <i-col span="11">
                <Form-item label="结束时间" prop="orderEndDate">
                    <Date-picker v-model="moduleRepairRocord.orderEndDate" type="datetime" placeholder="结束时间" :transfer="true"></Date-picker>
                </Form-item>
            </i-col>
        </Row>
        <Row>
            <i-col span="11">
                <Form-item label="故障类型" prop="faultDesc">
                    <i-input v-model="moduleRepairRocord.faultDesc" icon="md-arrow-dropdown-circle" @on-click="typeTree" placeholder="故障类型"></i-input>
                </Form-item>
            </i-col>
            <i-col span="11">
                <Form-item label="故障代码" prop="faultCode">
                    <i-input v-model="moduleRepairRocord.faultCode" placeholder="故障类型" disabled></i-input>
                </Form-item>
            </i-col>
        </Row>
        <Row>
            <i-col span="11">
                <Form-item label="故障描述" prop="recordDescr">
                    <i-input type="textarea" v-model="moduleRepairRocord.recordDescr" placeholder="故障描述"></i-input>
                </Form-item>
            </i-col>
            <i-col span="11">
                <Form-item label="解决方法" prop="solution">
                    <i-input type="textarea" v-model="moduleRepairRocord.solution" placeholder="解决方法"></i-input>
                </Form-item>
            </i-col>
        </Row>
        <Row>
            <i-col span="11">
                <Form-item label="备注" prop="remark">
                    <i-input type="textarea" v-model="moduleRepairRocord.remark" placeholder="备注"></i-input>
                </Form-item>
            </i-col>
        </Row>
        <Row>
            <i-col span="11" align="center">
                <i-button type="primary" @click="addRepairRecord" style="width: 100px">确认调整</i-button>
            </i-col>
        </Row>
    </i-form>
</div>
<div id="faultTypeLayer" style="display: none;padding:10px;">
    <ul id="faultTypeTree" class="ztree"></ul>
</div>

<script>
    var moldId = getQueryString("moldId");
    var ticketId = getQueryString('ticketId');
    var setting2 = {
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "typePid",
                rootPId: 0
            },
            key: {
                url: "nourl",
                name: "typeName" //name 与 typeName 绑定
            }
        }
    };
    var deptTree;
    var faultTree2;
    /**
     * 备件包
     */
    $(function () {
        //获取基本信息
        vm.getInfo();
        vm.getFaultTypeTree();
    });

    //设备图片
    var vm = new Vue({
        el: '#rrapp',
        data: {
            moduleRepairRocord: {
                useTeam: '',
                isError: '',
                checkDate: '',
                resultCheckUser: '',
                resultCheck: '',
                dealMethod: '',
                orderAcceptDate: '',
                orderExecuteDate: '',
                taskDate: '',
                orderExecuteUser: '',
                approveDate: '',
                approveUser: '',
                approveDeal: '',
                status: '',
                faultDes: '',
                faultType: '',
                faultCode: '',
                report: '',
                moduleNo: '',
                moldNo: '',
                repairCode: '',
                workshop: '',
                id: '',
            },
            repairRecordParam: {
                ticketId: ticketId, // 工单ID
                type: '',
                typeDesc: '', // 类型描述
                recordDescr: '',
                reason: '',
                solution: '',
                remark: ''
            },
            q: {
                name: '',
                modType: '',
            },
            replaceDate: '',//替换时间
        },
        methods: {
            getModuleArchives: function () {
                openWindow({
                    type: 2,
                    title: '<i class="fa fa-file-text-o"></i> 选择模具',
                    content: '../module/moduleArchiveSelect.html',
                    btn: ['确定', '取消'],
                    btn1: function (index) {
                        var iframeWin = window["layui-layer-iframe" + index];
                        var res = iframeWin.getModuleArchives();
                        if (!res) {
                            iview.Message.error("请选择一条记录");
                        } else {
                            vm.moduleRepairRocord.moduleNo = res.moduleNo;
                            vm.moduleRepairRocord.moldId = res.id;
                            vm.moduleRepairRocord.workshop = res.subShop;//车间id
                            layer.close(index);
                        }
                    }
                })
            },
            getInfo: function () {
                Ajax.request({
                    url: "../modulerepairrocord/info/" + ticketId,
                    async: false,
                    successCallback: function (r) {
                        vm.moduleRepairRocord = r.moduleRepairRocord;
                        vm.moduleRepairRocord.repairDate = dateFtt(r.moduleRepairRocord.repairDate);
                    }
                });
            },
            addRepairRecord: function () {
                // 调整日期格式
                if (vm.moduleRepairRocord.orderExecuteDate) {
                    vm.moduleRepairRocord.orderExecuteDate = gmt2DateTimeStr(vm.moduleRepairRocord.orderExecuteDate);
                }
                if (vm.moduleRepairRocord.orderEndDate) {
                    vm.moduleRepairRocord.orderEndDate = gmt2DateTimeStr(vm.moduleRepairRocord.orderEndDate);
                }
                // 添加维修记录
                var url = "../modulerepairrocord/addRepairRecord";
                Ajax.request({
                    url: url,
                    params: JSON.stringify(vm.moduleRepairRocord),
                    type: "POST",
                    contentType: "application/json",
                    successCallback: function (r) {
                        alert('调整成功，即将关闭！');
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭当前页
                        }, 2000);
                    }
                });
            },
            typeTree: function () {
                openWindow({
                    title: "选择故障类型",
                    area: ['300px', '450px'],
                    content: jQuery("#faultTypeLayer"),
                    btn: ['确定', '取消'],
                    btn1: function (index) {
                        var node = faultTree2.getSelectedNodes();
                        //选择上级部门
                        vm.moduleRepairRocord.faultType = node[0].id;
                        vm.moduleRepairRocord.faultCode = node[0].faultCode;
                        vm.moduleRepairRocord.faultDesc = node[0].typeName;
                        layer.close(index);
                    }
                });
            },
            getFaultTypeTree: function () {
                //加载故障类型树
                Ajax.request({
                    url: "../faulttype/select?category=2",
                    async: true,
                    successCallback: function (r) {
                        var tree = r.faultList;
                        faultTree2 = $.fn.zTree.init($("#faultTypeTree"), setting2, tree);
                    }
                });
            },
        }
    });


    function dateFtt(dateStr) {
        if (dateStr != null && dateStr != "null") {
            var date = new Date(dateStr);//当前时间
            var month = zeroFill(date.getMonth() + 1);//月
            var day = zeroFill(date.getDate());//日
            var hour = zeroFill(date.getHours());//时
            var minute = zeroFill(date.getMinutes());//分
            var second = zeroFill(date.getSeconds());//秒

            //当前时间
            var curTime = date.getFullYear() + "-" + month + "-" + day
                + " " + hour + ":" + minute + ":" + second;

            return curTime;
        }
    }
</script>
</body>
</html>
